﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CCWOnline.WebControls;
using LLFM.CAT.Service;
using LLFM.CAT.Model;
using Common.Enums;

public partial class Admin_Product_ProductList : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void Pager_PageChanging(object sender, PageChangingEventArgs e)
    {
        BindList(e.NewStartRecordIndex, Pager.PageSize);
    }

    private void BindList(int start, int number)
    {
        int count ;
        int pageCount;
        productRepeater.DataSource = ProductsService.GetProductListForPage(1,Pager.PageIndex, Pager.PageSize,out count,out pageCount);
        productRepeater.DataBind();
        Pager.RecordCount = count;
    }

    protected void ProductItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            M_Products product = (M_Products)e.Item.DataItem;
            Literal seriesLiteral = (Literal)e.Item.FindControl("SeriesLiteral");
            seriesLiteral.Text = SeriesService.GetSeriesById(product.SeriesId).Name;
            Literal statusLiteral = (Literal)e.Item.FindControl("statusLiteral");
            statusLiteral.Text = ((StatusEnum)product.Status).ToString();
            LinkButton modifyBtn = (LinkButton)e.Item.FindControl("modify");
            modifyBtn.CommandArgument = product.Id.ToString();
            LinkButton imgList = (LinkButton)e.Item.FindControl("imgList");
            imgList.CommandArgument = product.Id.ToString();
        }
    }

    protected void ProductItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "modify")
        {
            int productId = Common.TypeParse.StrToInt(e.CommandArgument,0);
            Response.Redirect("ModifyProduct.aspx?productId="+productId);
        }
        else if (e.CommandName == "imagList")
        {

            int productId = Common.TypeParse.StrToInt(e.CommandArgument, 0);
            Response.Redirect("ProductImagList.aspx?productId=" + productId);
        }
    }
}